home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / Kludges.subproj / FontWell.m < prev    next >
Encoding:
Text File  |  1994-11-20  |  4.2 KB  |  165 lines

  1. /* This file has been modified by Rohit Khare, 10/31/94 */
  2. /*
  3.  * Copyright (c) 1992 Athena Design, Inc. and David Pollak  
  4.  *
  5.  *            ALL RIGHTS RESERVED       
  6.  * 
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. Neither the name of the company (Athena Design) nor the names of its 
  17.  *    employees may be used to endorse or promote products derived from this 
  18.  *    software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY ATHENA DESIGN ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL ATHENA DESIGN BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33.  
  34. #import <appkit/publicWraps.h>
  35. #import <appkit/Font.h>
  36. #import <dpsclient/psops.h>
  37. #import <appkit/ActionCell.h>
  38. #import <appkit/FontManager.h>
  39. #import <appkit/Application.h>
  40.  
  41. #import "FontWell.h"
  42. #import "DPFontPanel.h"
  43.  
  44. inline double max(double n1,double n2)
  45. {
  46.     if (n1 > n2) return n1;
  47.     return n2;
  48.     }
  49.     
  50. @implementation FontWell
  51.  
  52. - initFrame:(const NXRect *)re
  53. {
  54.     
  55.     [super initFrame:re];
  56.     [self setCell:[[ActionCell alloc] init]];
  57.     theFont = [Font userFontOfSize:12.0 matrix:NX_IDENTITYMATRIX];
  58.     [self setFlipped:NO];
  59.     return self;
  60.     }
  61.     
  62. - drawSelf:(const NXRect *)re :(int)n
  63. {
  64.     NXRect r1;
  65.     char tmp[200];
  66.     
  67.     if (fontObj) return self;
  68.     
  69.     PSgsave();
  70.     PSrectclip(re -> origin.x,re -> origin.y,re -> size.width,re -> size.height);
  71.     
  72.     //NXEraseRect(re);
  73.     [self getBounds:&r1];
  74.     NXDrawWhiteBezel(&r1, re);
  75.     NXSetColor(NX_COLORBLACK);
  76.     [theFont set];
  77.     
  78.     PSrectclip(re -> origin.x + 2,re -> origin.y + 2,re -> size.width - 4,
  79.         re -> size.height - 4);
  80.     if (theStr) {
  81.         sprintf(tmp,"%s %g pt. is %s",
  82.                 [theFont name], [theFont pointSize],theStr);
  83.     } else {
  84.         sprintf(tmp,"%s %g pt.",[theFont name],[theFont pointSize]);
  85.     }
  86.     PSmoveto(max(2.0, (bounds.size.width-[theFont getWidthOf:tmp])/2.0),
  87.         max(2.0, (bounds.size.height - [theFont pointSize])/2.0));
  88.     PSshow(tmp);
  89.     //PScharpath(tmp,1);
  90.     //PSfill();
  91.     
  92.     PSgrestore();
  93.     PSflush();
  94.     
  95.     return self;
  96. }
  97.  
  98. - font
  99. {
  100.     return fontObj ? [superview font] : theFont;
  101. }
  102.  
  103. // proprietary extensions, RK, 10/31/94
  104. id proposedFont; // Global
  105. - proposedFont {return proposedFont;}
  106. - acceptFont:font atPoint:(NXPoint *)p
  107. {
  108.     id tid;
  109.     
  110.     if (![self isEnabled]) return nil;
  111.     proposedFont = font;
  112.     if ([self action] && [self target]) {
  113.         if ([self sendAction:[self action] to:[self target]] == nil)
  114.             return self;
  115.     }
  116.     
  117.     [self setFont:font];
  118.     if (fontObj) {
  119.         tid = [superview font];
  120.     
  121.         if ([tid matrix] != NX_IDENTITYMATRIX)
  122.             tid = [Font newFont:[tid name] size:[tid pointSize] matrix:NX_IDENTITYMATRIX];
  123.         
  124.         if (font != tid) [[FontManager new] setSelFont:font isMultiple:NO];
  125.     }
  126.     
  127.     return self;
  128. }
  129.     
  130. - setFont:font
  131. {
  132.     if (![self isEnabled]) return nil;
  133.     if ([font matrix] != NX_IDENTITYMATRIX)
  134.         font = [Font newFont:[font name] size:[font pointSize] matrix:NX_IDENTITYMATRIX];
  135.     theFont = font;
  136.     [self display];
  137.     return self;
  138. }
  139.     
  140. - mouseDown:(NXEvent *)ev
  141. {
  142.      [DPFontPanel dragFont:(fontObj ? [superview font] : theFont) withEvent:ev fromView:self];
  143.     
  144.     return self;
  145. }
  146.  
  147. - setFontObj:(id *)fo
  148. {
  149.     fontObj = fo;
  150.     return self;
  151. }
  152.  
  153. - setLastPreview:(char **)lp
  154. {
  155.     lastPreview = lp;
  156.     return self;
  157. }
  158. - setStr:(NXAtom)newStr
  159. {
  160.     theStr=newStr;
  161.     return self;
  162. }
  163.  
  164. @end
  165.